//
//  PushHelper.m
//  DeyiLife
//
//  Created by zxin on 15/8/7.
//  Copyright (c) 2015年 Deyi. All rights reserved.
//

#import "PushHelper.h"


#define kPushAppId           @"Wpw7JDuoMa9XNNyulZeEQ1"
#define kPushAppKey          @"L6Pm0xrUMP9WuFGWdfFXAA"
#define kPushAppSecret       @"KGIgUrGtQz8sKp7SATzyr6"


@implementation PushHelper

+ (void)registerRemoteNotification {
#ifdef __IPHONE_8_0
    if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0) {
        if ([[UIApplication sharedApplication] respondsToSelector:@selector(registerUserNotificationSettings:)]) {
            UIUserNotificationSettings *settings = [UIUserNotificationSettings settingsForTypes:UIUserNotificationTypeBadge|UIUserNotificationTypeSound|UIUserNotificationTypeAlert categories:nil];
            [[UIApplication sharedApplication] registerUserNotificationSettings:settings];
            [[UIApplication sharedApplication] registerForRemoteNotifications];
        }
    } else {
        UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert|
                                                                       UIRemoteNotificationTypeSound|
                                                                       UIRemoteNotificationTypeBadge);
        [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
    }
#else
    UIRemoteNotificationType apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert|
                                                                   UIRemoteNotificationTypeSound|
                                                                   UIRemoteNotificationTypeBadge);
    if ([UserData nodisturb]) {
        apn_type = (UIRemoteNotificationType)(UIRemoteNotificationTypeAlert|
                                              UIRemoteNotificationTypeBadge);
    }
    [[UIApplication sharedApplication] registerForRemoteNotificationTypes:apn_type];
#endif
}

+ (void)startSDKWithDelegate:(id)delegate {
    NSError *err = nil;
    //[1-1]:通过 AppId、 appKey 、appSecret 启动SDK
  //  [GeTuiSdk startSdkWithAppId:kPushAppId appKey:kPushAppKey appSecret:kPushAppSecret delegate:delegate error:&err];
    [GeTuiSdk startSdkWithAppId:kPushAppId appKey:kPushAppKey appSecret:kPushAppSecret delegate:delegate];
    //[1-2]:设置是否后台运行开关
    [GeTuiSdk runBackgroundEnable:YES];
    //[1-3]:设置电子围栏功能，开启LBS定位服务 和 是否允许SDK 弹出用户定位请求
    [GeTuiSdk lbsLocationEnable:NO andUserVerify:NO];
    
    if (err) {
        NSLog(@"%@", [NSString stringWithFormat:@"%@", [err localizedDescription]]);
    }
}

+ (void)registerDeviceToken:(NSString *)deviceToken {
    [GeTuiSdk registerDeviceToken:deviceToken];
}

+ (void)resume {
    [GeTuiSdk resume];
}

+ (void)stop {
   // [GeTuiSdk enterBackground];
    [GeTuiSdk  runBackgroundEnable:NO];
}

+ (void)enterBackground {
   // [GeTuiSdk enterBackground];
    [GeTuiSdk runBackgroundEnable:YES];
}

@end
